/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.grnt.common;

/**
 *
 * It is an abstract class. And this bean implement operation state semantic.In this
 * abstract class there are three method must be implemented. one is isDirty another
 * is commit method third method is rollback.
 * @author sayid
 */

public abstract class OptStatBean {
	boolean active = true;

	/**
	 * Default constructure.
	 */
	public OptStatBean() {
	}

	/**
	 * If any function call this method, the OptStatBean's instance object's
	 * active filed will be marked false;
	 */
	public void kill() {
		active = false;
	}

	/**
	 *
	 * Default instance's processing is return active filed value directly.
	 * But the subclass always overrid this method.
	 * @return
	 */
	public boolean isActive() {
		return this.active;
	}

	/**
	 *
	 * It accomplishes if the object has been modified semantic.
	 * @return It is ture when object is modified.
	 */
	public abstract boolean isDirty();

	/**
	 *
	 * It accomplishes commit semantic.
	 * @throws org.grnt.common.OptStatBean.OptStateException
	 */
	public abstract void commit() throws OptStateException;

	/**
	 *
	 * It accomplishes rollback semantic.
	 * @throws org.grnt.common.OptStatBean.OptStateException
	 */
	public abstract void rollback() throws OptStateException;

	/**
	 *
	 * It is a Exception class thrown by OptStatBean.
	 */
	public class OptStateException extends Exception{
		/**
		 *
		 */
		public OptStateException() {
			super();
		}
		/**
		 *
		 * @param message
		 */
		public OptStateException(String message) {
			super(message);
		}
		/**
		 *
		 * @param message
		 * @param cause
		 */
		public OptStateException(String message, Throwable cause) {
			super(message, cause);
		}
	}
}
